﻿@{
    ViewBag.Title = "MyGoods";
}
@section Styles{
    <link rel="stylesheet" type="text/css" href="/css/quan_index.css">
}

@section Scripts{
    <script src="/Scripts/sys/lib/common_raw.js"></script>
    <script src="~/Scripts/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="~/Scripts/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="~/Scripts/plugins/layer/layer.min.js"></script>
    <script>

        $(function () {
            initAcTable();


            $('#aMyProduct').click(function(){
                initMyProductTable();
            })

            $('#submit').click(submit)
            $('#deleteProduct').click(deleteProduct);

            $('#checkbox-2').change(function () {

                if ($('#checkbox-2').is(':checked')) {
                    // $('#productList').show();

                }
            })

            $('#addProduct').click(addProduct);


        })

        function addProduct() {

            var pids = "";
            var items = $('input[name="btSelectItem"]:checked').each(function () {
                pids += $(this).val() + ',';

            });

            common.invokeApi(
                     "POST",
                     "/Product/AddMyShop",
                      { pids: pids },
                     function () { },
                     function (data) {
                         if (data.State = true) {
                             common.msg(data.Message, 1, function () { });
                         }
                         else {
                             common.msg(data.Message, 2, function () { });
                         }
                     },
                     function (data) {
                         common.msg(data.Message, 2, function () { });
                     },
                     function () { }
                     );

        }
        function deleteProduct(){
            var pids = "";
            var items = $('input[name="btDelSelectItem"]:checked').each(function () {
                pids += $(this).val() + ',';

            });

            if(pids.length<=0)
            {
                alert("请选择要删除的商品");
                return false;
            }
            if(confirm("确定要删除选中的商品吗？"))
            {



                common.invokeApi(
                         "POST",
                         "/Product/DeleteMyProduct",
                          { pids: pids },
                         function () { },
                         function (data) {
                             if (data.State = true) {
                                 common.msg(data.Message, 1, function () { });
                                 initMyProductTable();
                             }
                             else {
                                 common.msg(data.Message, 2, function () { });
                             }
                         },
                         function (data) {
                             common.msg(data.Message, 2, function () { });
                         },
                         function () { }
                         );
            }
        }


        function ClassSearch(b, b2) {

            $("#shopclass").find("span a").removeClass("red");
            $(b2).addClass("red");

            CurrentIndex = 0;
            cid = b;
            SearchWord = "";
            $("#search").val("");
            $("#productlist").html("");
            initAcTable();
        }
        cid = 0;
        orderby = 0;
        function initAcTable() {
            $('#acc_tb').bootstrapTable('destroy');
            common.initAcTable("acc_tb", "toolbar", "post", "/Product/GetProducts_table?cid=" + cid + '&oid=' + orderby,
                function (data) {
                    if (!data.State) {
                        common.msg(data.Message, 1);
                    }
                },
                function (e) { },
                true, true, false, 10, 1, "[10,20,30,50]", { keyword: $("#keyword").val() });
        }

        function initMyProductTable() {
            $('#acc_tb2').bootstrapTable('destroy');
            common.initAcTable("acc_tb2", "toolbar", "post", "/Product/GetMyProduct",
                function (data) {
                    if (!data.State) {
                        common.msg(data.Message, 1);
                    }
                },
                function (e) { },
                true, true, false, 10, 1, "[10,20,30,50]", { keyword: $("#keyword").val() });
        }


        function submit() {

            var types = "";
            var items = $('input[name="type"]:checked').each(function () {
                types += $(this).val() + ",";


            })


            common.invokeApi(
                     "POST",
                     "/Product/collecting_source_type",
                      { type: types },
                     function () { },
                     function (data) {
                         if (data.State = true) {
                             common.msg(data.Message, 1, function () { });
                         }
                         else {
                             common.msg(data.Message, 2, function () { });
                         }
                     },
                     function (data) {
                         common.msg(data.Message, 2, function () { });
                     },
                     function () { }
                     );
        }

        function pictUrlFormatter(index, row) {
            var html = "<img style='width:100px' src='" + row.pictUrl + "'/>";
            return html;
        }
        function sellingFormatter(index, row) {
            var html = row.couponAmount + parseFloat(row.Price);
            return html;
        }
        function checkFormatter(index, row) {
            var html = " <div class=\"chbox\">";
            html += "  <div class=\"checkbox-nice\">";
            html += "<input type=\"checkbox\" name=\"btSelectItem\" id=\"cb-" + index + "\" value=\"" + row.auctionId + "\"  />";
            html += "<label for=\"cb-" + index + "\"></label> </div> </div>";

            //<input data-index="0" name="btSelectItem" type="checkbox" value="0">
            // html = '<input data-index="' + index + '" name="btSelectItem" type="checkbox" value="' + row.auctionId + '">';

            return html;
        }
        function checkDelFormatter(index, row) {
            var html = " <div class=\"chbox\">";
            html += "  <div class=\"checkbox-nice\">";
            html += "<input type=\"checkbox\" name=\"btDelSelectItem\" id=\"cb-del" + index + "\" value=\"" + row.id + "\"  />";
            html += "<label for=\"cb-del" + index + "\"></label> </div> </div>";

            //<input data-index="0" name="btSelectItem" type="checkbox" value="0">
            // html = '<input data-index="' + index + '" name="btSelectItem" type="checkbox" value="' + row.auctionId + '">';

            return html;
        }
        function Order(id, obj) {
            $(".goods-pages-fil").find("span").removeClass("cur");
            $(obj).addClass("cur");
            $(".goods-pages-fil").find("span").each(function () {
                if ($(this).attr("data-px") == "sell") {
                    $(this).find("a").html("销量");
                }
                if ($(this).attr("data-px") == "yjdown") {
                    $(this).find("a").html("佣金比例");
                }
                if ($(this).attr("data-px") == "jgup") {
                    $(this).find("a").html("价格");
                }
            })
            $("#productlist").html("");
            switch (id) {
                case 3:
                    $(obj).find("a").html("销量从高到底");
                    break;
                case 4:
                    $(obj).find("a").html("佣金比例从高到底");

                    break;
                case 5:
                    $(obj).find("a").html("价格从低到高");
                    break;
            }
            CurrentIndex = 0;
            orderby = id;
            initAcTable();
        }

    </script>

}
<div class="row" style="opacity: 1;">
    <div class="col-lg-12">
        <div class="row">
            <div class="col-lg-12">
                <ol class="breadcrumb">
                    <li><a href="#">首页</a></li>
                    <li class="active"><span>我的商品</span></li>
                </ol>
                <h1>我的商品</h1>
            </div>
        </div>
        <div class="row">

            <div class="col-lg-12">
                <div class="main-box">
                    <header class="main-box-header clearfix">
                        <h2>采集源设置</h2>
                    </header>
                    <div class="main-box-body clearfix">

                        <div class="form-group">
                            <label>选择要采集的渠道</label>
                            <div class="checkbox-nice">
                                @{
                                    if (((string)ViewBag.Type).Contains("1"))
                                    {
                                        <input type="checkbox" id="checkbox-1" name="type" value="1" checked>
                                    }
                                    else
                                    {
                                        <input type="checkbox" id="checkbox-1" name="type" value="1">
                                    }
                                }


                                @*<input type="checkbox" id="checkbox-1" name="type" value="1" >*@
                                <label for="checkbox-1">
                                    纵横联盟精选商品
                                </label>
                            </div>
                            <div class="checkbox-nice">
                                @*<input type="checkbox" id="checkbox-2" name="type" value="0">*@

                                @{
                                    if (((string)ViewBag.Type).Contains("0"))
                                    {
                                        <input type="checkbox" id="checkbox-2" name="type" value="0" checked>
                                    }
                                    else
                                    {
                                        <input type="checkbox" id="checkbox-2" name="type" value="0">
                                    }

                                }
                                <label for="checkbox-2">
                                    自选商品
                                </label>
                            </div>

                        </div>
                        <div class="form-group">
                            <div class="col-lg-offset-2 col-lg-10">
                                <button id="submit" type="submit" class="btn btn-success">保存</button>
                            </div>
                        </div>



                    </div>
                </div>
            </div>
        </div>

        <div class="row" id="productList">


            <div class="col-lg-12">

                <div class="main-box clearfix">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab-home" data-toggle="tab" aria-expanded="true">产品库</a></li>
                        <li class=""><a href="#tab-accounts" data-toggle="tab" aria-expanded="false" id="aMyProduct">我的商品</a></li>

                    </ul>
                    <div class="tab-content">




                        <div class="tab-pane fade active in" id="tab-home">


                            <header class="main-box-header clearfix">
                                <div class="main-top">

                                    <div class="goods-type-filter">
                                        <div class="goods-type">
                                            <div class="goods-type-main" id="shopclass">
                                                @foreach (var item in Model)
                                                {
                                                    <span><a href="#" onclick="ClassSearch(@item.ID,this)">@item.Name<b> (@item.Count) </b></a></span>
                                                }
                                            </div>
                                        </div>
                                    </div>

                                    <div class="goods-pages">
                                        <div class="goods-pages-fil clearfix">
                                            <span data-px="zh" id="zhonghe" class="pxclick cur" onclick="Order(1,this)"><a href="javascript:void(0);">综合</a></span>
                                            <span data-px="zx" class="pxclick " onclick="Order(2, this)"><a href="javascript:void(0);">最新</a></span>
                                            <span data-px="sell" class="pxclick " onclick="Order(3, this)"><a href="javascript:void(0);">销量</a></span>
                                            <span data-px="yjdown" class="pxclick " onclick="Order(4, this)"><a href="javascript:void(0);">佣金比例</a></span>
                                            <span data-px="jgup" class="pxclick " onclick="Order(5, this)"><a href="javascript:void(0);">价格</a></span>
                                        </div>
                                    </div>
                                </div>

                                <a href="#" class="btn btn-primary " id="addProduct">
                                    添加商品
                                </a>

                            </header>
                            <div class="main-box-body clearfix" id="tab-home">
                                <div class="table-responsive">



                                    <table class="table" id="acc_tb" data-pagination="true" @*data-toggle="table"*@>
                                        <thead>
                                            <tr>
                                                @*<th data-field="auctionId" data-formatter="checkFormatter">
                                                        <input type="checkbox" id="ck_all">
                                                        <label for="ck_all"></label>

                                                    </th>*@



                                                <th class="bs-checkbox " style="text-align: center; vertical-align: middle; width: 36px; " data-field="auctionId" data-formatter="checkFormatter" tabindex="0">
                                                    <div class="th-inner chbox ">
                                                        <div class="checkbox-nice">
                                                            <input name="btSelectAll" id="btSelectAll" type="checkbox">
                                                            <label for="btSelectAll"></label>
                                                        </div>
                                                    </div>
                                                    @*<div class="fht-cell" style="width: 35px;"></div>*@

                                                </th>

                                                <th data-field="pictUrl" data-formatter="pictUrlFormatter">图片</th>
                                                <th data-field="title">标题/属性</th>

                                                <th data-field="Price">券后价</th>
                                                <th data-field="couponAmount">优惠券</th>
                                                <th data-field="tkRate">佣金比率</th>
                                                <th>开始/结束时间</th>

                                            </tr>
                                        </thead>

                                    </table>
                                </div>

                            </div>
                        </div>

                        <div class="tab-pane fade " id="tab-accounts">


                            <header class="main-box-header clearfix">

                                <button type="button" id="deleteProduct" class="btn btn-danger">删除</button>

                            </header>



                            <div class="table-responsive">
                                <table class="table" id="acc_tb2" data-pagination="true" @*data-toggle="table"*@>
                                    <thead>
                                        <tr>




                                            <th class="bs-checkbox " style="text-align: center; vertical-align: middle; width: 36px; " data-field="id" data-formatter="checkDelFormatter" tabindex="0">
                                                @*<div class="th-inner chbox ">
                                                        <div class="checkbox-nice">
                                                            <input name="btSelectAll"  type="checkbox">
                                                            <label for="btDelSelectAll"></label>
                                                        </div>
                                                    </div>*@
                                                @*<div class="fht-cell" style="width: 35px;"></div>*@

                                            </th>

                                            <th data-field="pictUrl" data-formatter="pictUrlFormatter">图片</th>
                                            <th data-field="title">标题/属性</th>

                                            <th data-field="Price">券后价</th>
                                            <th data-field="couponAmount">优惠券</th>
                                            <th data-field="tkRate">佣金比率</th>
                                            <th>开始/结束时间</th>

                                        </tr>
                                    </thead>

                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>




    </div>
</div>

